package com.seadragon.app.ksr.normalizer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seadragon.app.ksr.util.CacheManager;

@Service("addressLine1Normalizer")
public class AddressLine1Normalizer implements Normalizer {
	private Logger logger = LoggerFactory.getLogger(AddressLine1Normalizer.class);
	
	@Autowired
	private CacheManager cacheManager;

	/* (non-Javadoc)
	 * @see com.seadragon.app.ksr.normalizer.Normalizer#normalize(java.lang.String)
	 */
	@Override
	public String normalize(String route) {
		logger.info("Route: " + route);
		StringBuffer sb = new StringBuffer();
		String[] fields = route.trim().split(" ");
		for(String field : fields){
			String std = cacheManager.standardizeAddressLine1(field);
			if(std != null){
				sb.append(std);
			}else{
				sb.append(field);
			}
			sb.append(" ");
		}
		logger.info("Standardized Route: " + sb.toString().trim());
		return sb.toString().trim().toUpperCase();
	}
}
